import 'package:flutter/material.dart';
import 'package:x3_charts_core/chart_painter/rectangle_chart_painter.dart';

import '../x3_charts_core.dart';

///**
///* @fileName: rounded_rectangle_chart_widget
///* @author: hrongyong
///* @date-time: 3/16/21 8:59 AM
///* @email: hrongyong@gmail.com
///* description: 矩形图小部件
///* <fileName> <author> <date-time> <email> <description>
///* 文件名 作者姓名 创建时间 作者邮箱 文件描述
///*/

class RectangleChartWidget extends StatefulWidget {
  ///图表数据
  final List<GeneralChartModel> chartList;

  ///x轴文本描述大小
  final double xAxisSize;

  ///背景颜色
  final Color backgroundColor;

  ///是否开启圆角
  final bool turnOnFillet;

  RectangleChartWidget({
    @required this.chartList,
    @required this.xAxisSize,
    this.backgroundColor = Colors.white,
    this.turnOnFillet = true,
  });

  @override
  _RectangleChartWidgetState createState() => _RectangleChartWidgetState();
}

class _RectangleChartWidgetState extends State<RectangleChartWidget> with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(milliseconds: 1000),
      vsync: this,
    )..forward();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        return CustomPaint(
          size: Size(constraints.maxWidth, constraints.maxHeight),
          painter: RectangleChartPainter(
            chartList: widget.chartList,
            repaint: _controller,
            xAxisSize: widget.xAxisSize,
            backgroundColor: widget.backgroundColor,
            turnOnFillet: widget.turnOnFillet,
          ),
        );
      },
    );
  }
}
